﻿using System;
using EPiServer.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EPiServer.Tests.UnitTests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class EPiServerInitializedTest : EPiServerUnitTest
    {
        [TestMethod]
        public void TestLanguageManagerInitialized()
        {
            Assert.IsTrue(
                LanguageManager.Instance.Translate("/testtranslation","en")=="Test translation",
                "LanguageManager returned unexpected value, translation failed");
        }

        [TestMethod]
        public void TestDataFactoryInitialized()
        {
            try
            {
                if(PageReference.IsNullOrEmpty(PageReference.StartPage) ||
                   PageReference.RootPage==PageReference.StartPage)
                {
                    Assert.Inconclusive("Unable to verify pages can be accessed through DataFactory because a start page has not been specified, or the start page points to the system root page");
                }

                var startPage = DataFactory.Instance.GetPage(PageReference.StartPage);

                Assert.IsNotNull(startPage, "DataFactory returned null when retrieving the start page");
                
                Assert.IsInstanceOfType(startPage,typeof(PageData), "Retrieved start page is not of type PageData");
            }
            catch (Exception ex)
            {
                Assert.Fail("DataFactory is not properly initialized: {0}", ex.Message);
            }
        }
    }
}
